package com.smartx.app.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.smartx.app.R;

public class MessageDialog extends DialogFragment implements View.OnClickListener{
    private TextView tvMessage;
    private Button btnOK;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //设置背景透明
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View view= LayoutInflater.from(getActivity()).inflate(R.layout.dialog_show_message, null);
        tvMessage= view.findViewById(R.id.message);
        btnOK= view.findViewById(R.id.ok_action);

        btnOK.setOnClickListener(this);

        Bundle bundle = getArguments();
        String message = bundle.getString("message","");
        tvMessage.setText(message);

        builder.setView(view);
        return builder.create();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ok_action:
                if (getTargetFragment()== null){
                    return;
                }
                Intent intent= new Intent();
                getTargetFragment().onActivityResult(this.getTargetRequestCode(), Activity.RESULT_OK, intent);
                break;
        }
    }
}
